import Taro from "@tarojs/taro";
import { ExpertProps } from "./expert";

// 活动列表

export type EventListProps = {
    beans: number // ?帮豆
    end_date: string
    event_end: string
    event_start: string
    id: number
    no: string
    img: string
    location: string
    create_time: string
    verify_time: string
    max_participants: number
    official: boolean
    partin: boolean // ?是否已加入
    points: number // ?积分
    priority: number
    start_date: string
    status: 1 | 0 | 2 // ? 0=待开始，1=报名中，2=已结束
    order_status: 0 | 1 | 2
    subtitle: string
    title: string
    partin_status: 0 | 1 // ?0=未满，1=已满
    description: string
    code: string // ?邀请码
    expert_list: ExpertProps[]
}

// ?活动列表
export function EventList() {
    return Taro.request({
        url: `/api/event/list`,
        method: 'GET'
    }).then<EventListProps[]>(res => res?.data)
}


// ?长期活动列表
export function LongEventList() {
    return Taro.request({
        url: `/api/event/longEvent`,
        method: 'GET'
    }).then<EventListProps[]>(res => res?.data)
}


// ?活动详情
export function EventDetail(params: {
    event_id: string | number
}) {
    return Taro.request({
        url: `/api/event/detail`,
        method: 'GET',
        data: params
    }).then<EventListProps>(res => res?.data)
}


// ?参与活动
export function EventJoin(params: {
    event_id: number | string
}) {
    return Taro.request({
        url: `/api/event/participate`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}


// ?充值配置
export type MoneyConfigProps = {
    create_time: string
    id: number
    money: number
    price: number
    type: 1 | 2
}
export function MoneyConfig(params: {
    type: 1 | 2 // ?1=帮豆，2=积分
}) {
    return Taro.request({
        url: `/api/money/config`,
        method: 'GET',
        data: params
    }).then<MoneyConfigProps[]>(res => res?.data)
}

// ?充值申请
export function MoneyApply(params: {
    beans: number | string
    config?: number
    remark?: string
}) {
    return Taro.request({
        url: `/api/money/apply`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}


// ?积分兑换
export function MoneyConvertPoints(params: {
    config: number
}) {
    return Taro.request({
        url: `/api/money/convertPoints`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}

// ?获取配置
export function UserConfig(params: {
    type: 1 | 4 | 6 // ? 1=获取专家价格范围 4=客服二维码 6=提现积分和现金的比例  积分/比例 = 可提现的金额
}) {
    return Taro.request({
        url: `/api/user/config`,
        method: 'POST',
        data: params
    }).then<any>(res => res?.data)
}